package cn.edu.xust.controller;

import cn.edu.xust.bean.AmmeterParameter;
import cn.edu.xust.communication.remote.AmmeterRemoteReader;
import cn.edu.xust.communication.server.cache.ChannelMap;
import cn.edu.xust.mapper.AmmeterParameterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @author ：huangxin
 * @modified ：
 * @since ：2020/03/28 17:25
 */
@RestController
@RequestMapping("/now")
public class AmmeterController {

    @Autowired
    private AmmeterParameterMapper ammeterParameterMapper;
    @Autowired
    private AmmeterRemoteReader ammeterRemoteReader;





    @RequestMapping(value = "/test/{ammeterId}")
    public List<AmmeterParameter> controller(@PathVariable(value = "ammeterId") String ammeterId) {
        List<String> list = new ArrayList<>();
        list.add(ammeterId);
        return ammeterRemoteReader.realTelemetry(list);
    }


    @PostMapping(value = "/meter")
    public List<AmmeterParameter> meter(@RequestBody List<String> deviceNumberList) {
        return ammeterRemoteReader.realMeter(deviceNumberList);
    }

    @PostMapping(value = "/telemety")
    public List<AmmeterParameter> telemety(@RequestBody List<String> deviceNumberList) {
        return ammeterRemoteReader.realTelemetry(deviceNumberList);
    }

    @PostMapping(value = "/region")
    public List<AmmeterParameter> region(@RequestBody List<String> deviceNumberList) {
        return ammeterRemoteReader.realRegion(deviceNumberList);
    }

    @PostMapping(value = "/deviceState")
    public List<AmmeterParameter> deviceState(@RequestBody List<String> deviceNumberList) {
        return ammeterRemoteReader.realState(deviceNumberList);
    }

    @GetMapping(value = "/allDeviceNumber")
    public List<String> allDeviceNumber() {
        List<String> list = new LinkedList<>();
        for (String s : ChannelMap.getDeviceNumMap2DeviceIp().keySet()) {
            list.add(s);
        }
        return list;
    }


}
